home *** CD-ROM | disk | FTP | other *** search
- package DynaButtonsComp;
-
- import com.netobjects.nfc.api.CStringArray;
- import com.netobjects.nfc.api.ComponentApp;
- import com.netobjects.nfc.api.DAssetManager;
- import com.netobjects.nfc.api.DDrawJava;
- import com.netobjects.nfc.api.DFont;
- import com.netobjects.nfc.api.DLayout;
- import com.netobjects.nfc.api.DRect;
- import com.netobjects.nfc.api.DSite;
- import com.netobjects.nfc.api.DSize;
- import com.netobjects.nfc.api.DStyle;
- import com.netobjects.nfc.api.IDInspector;
- import java.util.ResourceBundle;
-
- public class DynaButtonsComp extends ComponentApp {
- int backgroundStyle = 0;
- DAssetManager assMan = null;
- int upID = 0;
- int downID = 0;
- int backID = 0;
- String Orientation = "";
- String ButtonImage = "";
- String HighliteImage = "";
- String paramButtonImage = "";
- String paramHighliteImage = "";
- int backgroundColor = 0;
- String backgroundImage = "";
- String paramBackgroundImage = "";
- int textJustification = 0;
- int textAlignment = 0;
- int fontColor = 0;
- int highliteFontColor = 0;
- String buttonFont = "";
- boolean italic = false;
- boolean bold = false;
- int fontSize = 0;
- ButtonObject buttonList = null;
- DDrawJava theJavaApplet = null;
- String compImage = "";
- int imgX = 0;
- int imgY = 0;
- String indent = " ";
- // $FF: renamed from: cb java.lang.String
- String field_0;
-
- void checkList(ButtonObject list) {
- }
-
- protected void CopyOneAsset(String assetIDStr) {
- int assetID = Integer.parseInt(assetIDStr, 10);
- if (assetID != 0) {
- this.assMan.CopyAsset(assetID);
- }
-
- }
-
- private int countButtons(ButtonObject buttonList) {
- int num = 0;
-
- for(ButtonObject tempList = buttonList.getNext(); tempList != null; tempList = tempList.getNext()) {
- ++num;
- }
-
- return num;
- }
-
- private void debug(String out) {
- }
-
- private void modifyImageSize() {
- int width = 0;
- int height = 0;
- ButtonObject tempList = this.buttonList.getNext();
- if (this.Orientation.compareTo(ResourceBundle.getBundle("DynaButtonsComp").getString("Horizontal")) == 0) {
- for(width = this.countButtons(this.buttonList); tempList != null; tempList = tempList.getNext()) {
- if (height == 0) {
- height = 1;
- }
-
- if (tempList.getSubButtonsExist()) {
- int numSubButtons = this.countButtons(tempList.getSubButtons()) + 1;
- if (numSubButtons > height) {
- height = numSubButtons;
- }
- }
- }
- } else {
- height = this.countButtons(this.buttonList);
-
- for(int i = 1; tempList != null; ++i) {
- if (width == 0) {
- width = 1;
- }
-
- if (tempList.getSubButtonsExist()) {
- width = 2;
- int numSubButtons = this.countButtons(tempList.getSubButtons()) + i;
- if (numSubButtons > height) {
- height = numSubButtons;
- }
- }
-
- tempList = tempList.getNext();
- }
- }
-
- this.theJavaApplet.SetSize(width * this.imgX, height * this.imgY);
- }
-
- private void modifyNumButtons(int newLength, ButtonObject currentList) {
- int currentLength = this.countButtons(currentList);
- if (newLength < currentLength) {
- for(int i = 0; i < newLength; ++i) {
- currentList = currentList.getNext();
- }
-
- currentList.setNext((ButtonObject)null);
- } else if (newLength > currentLength) {
- for(int i = 0; i < newLength; ++i) {
- if (currentList.getNext() == null) {
- currentList.setNext(new ButtonObject());
- }
-
- currentList = currentList.getNext();
- }
- }
-
- }
-
- public void onCopy() {
- this.debug("in onCopy()");
- this.Orientation = new String(this.Orientation);
- this.ButtonImage = new String(this.ButtonImage);
- this.HighliteImage = new String(this.HighliteImage);
- this.paramButtonImage = new String(this.paramButtonImage);
- this.paramHighliteImage = new String(this.paramHighliteImage);
- this.backgroundImage = new String(this.backgroundImage);
- this.buttonFont = new String(this.buttonFont);
- this.compImage = new String(this.compImage);
- this.indent = new String(this.indent);
- this.assMan.CopyAsset(this.upID);
- this.assMan.CopyAsset(this.downID);
- ButtonObject copyButtonList = new ButtonObject();
- ButtonObject copyTempList = copyButtonList;
- this.debug("<copy> length of original: " + this.countButtons(this.buttonList));
- ButtonObject tempList = this.buttonList.getNext();
- this.debug("about to copy list");
-
- for(int i = 1; tempList != null; ++i) {
- this.debug("in copy list");
- copyTempList.setNext(new ButtonObject());
- copyTempList = copyTempList.getNext();
- this.CopyOneAsset(tempList.getID());
- copyTempList.setID(tempList.getID());
- copyTempList.setText(tempList.getText());
- copyTempList.setURL(tempList.getURL());
- this.debug("copied: " + i);
- if (tempList.getSubButtonsExist()) {
- copyTempList.setSubButtonsExist(true);
- ButtonObject subList = tempList.getSubButtons().getNext();
- ButtonObject copySubList = copyTempList.getSubButtons();
-
- for(int j = 1; subList != null; ++j) {
- copySubList.setNext(new ButtonObject());
- copySubList = copySubList.getNext();
- this.CopyOneAsset(subList.getID());
- copySubList.setID(subList.getID());
- copySubList.setText(subList.getText());
- copySubList.setURL(subList.getURL());
- subList = subList.getNext();
- }
- }
-
- tempList = tempList.getNext();
- }
-
- this.buttonList = copyButtonList;
- }
-
- public void onDrop(DLayout layout, DRect r, int fDrop) {
- if (fDrop == 1) {
- this.theJavaApplet = new DDrawJava();
- this.field_0 = this.theJavaApplet.getCodeBase();
- this.compImage = this.field_0 + "DYNBUTTON.gif";
- this.theJavaApplet.SetStyle(1, 1);
- this.theJavaApplet.setStretch(2);
- this.buttonList = new ButtonObject();
- this.buttonList.setNext(new ButtonObject());
- this.theJavaApplet.setImageFile(this.compImage);
- this.theJavaApplet.setUsePictureText(true);
- this.theJavaApplet.setPictureText(ResourceBundle.getBundle("DynaButtonsComp").getString("Component_Name"));
- DSite site = layout.getSite();
- DStyle style = site.getCurrentStyle();
- DSize buttonSize = style.getButtonSize();
- int imX;
- int imY;
- if (buttonSize != null) {
- imX = buttonSize.getWidth();
- imY = buttonSize.getHeight();
- } else {
- imX = 100;
- imY = 35;
- }
-
- this.theJavaApplet.SetPositionRect(r.getLeft(), r.getTop(), r.getLeft() + imX, r.getTop() + imY);
- this.Orientation = ResourceBundle.getBundle("DynaButtonsComp").getString("Horizontal");
- this.theJavaApplet.setAppletFileName(this.field_0 + "DynaButtons.class");
- this.theJavaApplet.AddAdditionalAppletFile(this.field_0 + "PopButton.class");
- this.theJavaApplet.AddAdditionalAppletFile(this.field_0 + "PopObject.class");
- this.theJavaApplet.AddAdditionalAppletFile(this.field_0 + "DynaButtons.zip");
- layout.AddObject(this.theJavaApplet);
- }
-
- if (fDrop != 3 && fDrop != 4) {
- this.updateSiteLook(0);
- this.SetPropertyValues();
- }
-
- }
-
- protected void onFinalize() {
- this.RemoveAssets();
- ButtonObject tempList = this.buttonList.getNext();
-
- for(int i = 1; tempList != null; ++i) {
- this.RemoveOneAsset(tempList.getID());
- if (tempList.getSubButtonsExist()) {
- ButtonObject subList = tempList.getSubButtons().getNext();
-
- for(int j = 1; subList != null; ++j) {
- this.RemoveOneAsset(subList.getID());
- subList = subList.getNext();
- }
- }
-
- tempList = tempList.getNext();
- }
-
- }
-
- public void onInspect(CStringArray Names, CStringArray Types) {
- Names.Set(ResourceBundle.getBundle("DynaButtonsComp").getString("Orientation"));
- Types.Set("Set(" + ResourceBundle.getBundle("DynaButtonsComp").getString("Orientation_List") + ")");
- Names.Set(ResourceBundle.getBundle("DynaButtonsComp").getString("Number_of_Buttons"));
- Types.Set("Collection");
- ButtonObject tempList = this.buttonList.getNext();
-
- for(int i = 1; tempList != null; ++i) {
- if (tempList.getSubButtonsExist()) {
- Names.Set(ResourceBundle.getBundle("DynaButtonsComp").getString("Button") + " " + i);
- Types.Set("String");
- Names.Set(ResourceBundle.getBundle("DynaButtonsComp").getString("Use_Sub_Buttons") + " " + i);
- Types.Set("Set(" + ResourceBundle.getBundle("DynaButtonsComp").getString("Use_Sub_Button_List") + ")");
- Names.Set(ResourceBundle.getBundle("DynaButtonsComp").getString("Number_Sub_Buttons") + " " + i);
- Types.Set("Collection");
- ButtonObject subList = tempList.getSubButtons().getNext();
-
- for(int j = 1; subList != null; ++j) {
- Names.Set(this.indent + ResourceBundle.getBundle("DynaButtonsComp").getString("Sub_Button") + " " + i + "," + j);
- Types.Set("Link");
- subList = subList.getNext();
- }
- } else {
- Names.Set(ResourceBundle.getBundle("DynaButtonsComp").getString("Button") + " " + i);
- Types.Set("Link");
- Names.Set(ResourceBundle.getBundle("DynaButtonsComp").getString("Use_Sub_Buttons") + " " + i);
- Types.Set("Set(" + ResourceBundle.getBundle("DynaButtonsComp").getString("Use_Sub_Button_List") + ")");
- }
-
- tempList = tempList.getNext();
- }
-
- }
-
- public String onInstall(DAssetManager cam, String codebase) {
- this.assMan = cam;
- this.compImage = codebase + "DYNBUTTON.gif";
- return ResourceBundle.getBundle("DynaButtonsComp").getString("Component_Name");
- }
-
- public void onPublish(DAssetManager asm, int context) {
- this.updateSiteLook(context);
- this.setAllUrls(context);
- if (context == 1) {
- this.paramButtonImage = this.ButtonImage;
- this.paramHighliteImage = this.HighliteImage;
- this.paramBackgroundImage = this.backgroundImage;
- } else {
- this.paramButtonImage = this.ButtonImage;
- this.paramHighliteImage = this.HighliteImage;
- this.paramBackgroundImage = this.backgroundImage;
- }
-
- this.SetPropertyValues();
- DRect thePosition = this.theJavaApplet.getObjectRect();
- this.theJavaApplet.AddParam("X Position", "String", Integer.toString(thePosition.getLeft()));
- this.theJavaApplet.AddParam("Y Position", "String", Integer.toString(thePosition.getTop() + 7));
- }
-
- public String PropertyListener(String Event, String Value, int Get, int propIndex, IDInspector insp) {
- if (Get == 1) {
- if (Event.compareTo(ResourceBundle.getBundle("DynaButtonsComp").getString("Orientation")) == 0) {
- if (this.Orientation.compareTo(ResourceBundle.getBundle("DynaButtonsComp").getString("Horizontal")) == 0) {
- return "0";
- }
-
- return "1";
- }
-
- if (Event.compareTo(ResourceBundle.getBundle("DynaButtonsComp").getString("Number_of_Buttons")) == 0) {
- return Integer.toString(this.countButtons(this.buttonList));
- }
-
- ButtonObject tempList = this.buttonList.getNext();
-
- for(int i = 1; tempList != null; ++i) {
- if (Event.compareTo(ResourceBundle.getBundle("DynaButtonsComp").getString("Use_Sub_Buttons") + " " + i) == 0) {
- if (tempList.getSubButtonsExist()) {
- return "0";
- }
-
- return "1";
- }
-
- if (Event.compareTo(ResourceBundle.getBundle("DynaButtonsComp").getString("Button") + " " + i) == 0) {
- if (tempList.getSubButtonsExist()) {
- return tempList.getText();
- }
-
- return tempList.getID();
- }
-
- ButtonObject subList = tempList.getSubButtons();
- if (Event.compareTo(ResourceBundle.getBundle("DynaButtonsComp").getString("Number_Sub_Buttons") + " " + i) == 0) {
- return Integer.toString(this.countButtons(subList));
- }
-
- subList = subList.getNext();
-
- for(int j = 1; subList != null; ++j) {
- if (Event.compareTo(this.indent + ResourceBundle.getBundle("DynaButtonsComp").getString("Sub_Button") + " " + i + "," + j) == 0) {
- return subList.getID();
- }
-
- subList = subList.getNext();
- }
-
- tempList = tempList.getNext();
- }
- } else {
- if (Event.compareTo(ResourceBundle.getBundle("DynaButtonsComp").getString("Orientation")) == 0) {
- if (Value.compareTo("0") == 0) {
- this.Orientation = ResourceBundle.getBundle("DynaButtonsComp").getString("Horizontal");
- } else {
- this.Orientation = ResourceBundle.getBundle("DynaButtonsComp").getString("Vertical");
- }
-
- this.debug("\r\nrandom:");
- this.checkList(this.buttonList);
- this.modifyImageSize();
- } else if (Event.compareTo(ResourceBundle.getBundle("DynaButtonsComp").getString("Number_of_Buttons")) == 0) {
- int nBtn = Integer.parseInt(Value, 10);
- if (nBtn > 0) {
- int NumButtons = nBtn;
- if (nBtn > 20) {
- NumButtons = 20;
- }
-
- this.modifyNumButtons(NumButtons, this.buttonList);
- this.modifyImageSize();
- }
- } else {
- ButtonObject tempList = this.buttonList.getNext();
-
- for(int i = 1; tempList != null; ++i) {
- if (Event.compareTo(ResourceBundle.getBundle("DynaButtonsComp").getString("Button") + " " + i) == 0) {
- if (tempList.getSubButtonsExist()) {
- tempList.setText(Value);
- } else {
- tempList.setID(Value);
- tempList.setText(this.assMan.GetAssetName(Integer.parseInt(Value, 10)));
- }
- } else if (Event.compareTo(ResourceBundle.getBundle("DynaButtonsComp").getString("Use_Sub_Buttons") + " " + i) == 0) {
- if (Value.compareTo("0") == 0) {
- tempList.setSubButtonsExist(true);
- if (insp != null) {
- insp.OnPropertyChanged(-1);
- }
- } else {
- tempList.setSubButtonsExist(false);
- if (insp != null) {
- insp.OnPropertyChanged(-1);
- }
- }
-
- this.modifyImageSize();
- } else if (Event.compareTo(ResourceBundle.getBundle("DynaButtonsComp").getString("Number_Sub_Buttons") + " " + i) == 0) {
- int NumButtons = Integer.parseInt(Value, 10);
- if (NumButtons > 20) {
- NumButtons = 20;
- }
-
- this.modifyNumButtons(NumButtons, tempList.getSubButtons());
- this.modifyImageSize();
- } else {
- ButtonObject subList = tempList.getSubButtons().getNext();
-
- for(int j = 1; subList != null; ++j) {
- if (Event.compareTo(this.indent + ResourceBundle.getBundle("DynaButtonsComp").getString("Sub_Button") + " " + i + "," + j) == 0) {
- subList.setID(Value);
- subList.setText(this.assMan.GetAssetName(Integer.parseInt(Value, 10)));
- }
-
- subList = subList.getNext();
- }
- }
-
- tempList = tempList.getNext();
- }
- }
-
- this.SetPropertyValues();
- }
-
- return "";
- }
-
- protected void RemoveAssets() {
- if (this.upID != 0) {
- this.assMan.RemoveAsset(this.upID);
- this.assMan.RemoveAsset(this.downID);
- }
-
- if (this.backID != 0) {
- this.assMan.RemoveAsset(this.backID);
- }
-
- }
-
- protected void RemoveOneAsset(String assetIDStr) {
- int assetID = Integer.parseInt(assetIDStr, 10);
- if (assetID != 0) {
- this.assMan.RemoveAsset(assetID);
- }
-
- }
-
- private void setAllUrls(int context) {
- ButtonObject tempList = this.buttonList.getNext();
-
- for(int i = 1; tempList != null; ++i) {
- int assetID = Integer.parseInt(tempList.getID(), 10);
- String theURL = this.assMan.GetAssetRelativeLocation(assetID, context, 1);
- String theTarget = this.assMan.GetTargetFromLink(assetID);
- tempList.setURL(theURL);
- tempList.setTarget(theTarget);
- if (tempList.getSubButtonsExist()) {
- ButtonObject subList = tempList.getSubButtons().getNext();
-
- for(int j = 1; subList != null; ++j) {
- int subAssetID = Integer.parseInt(subList.getID(), 10);
- String subURL = this.assMan.GetAssetRelativeLocation(subAssetID, context, 1);
- String subTarget = this.assMan.GetTargetFromLink(subAssetID);
- subList.setURL(subURL);
- subList.setTarget(subTarget);
- subList = subList.getNext();
- }
- }
-
- tempList = tempList.getNext();
- }
-
- }
-
- void SetPropertyValues() {
- this.theJavaApplet.ResetParams();
- if (this.Orientation == ResourceBundle.getBundle("DynaButtonsComp").getString("Vertical")) {
- this.theJavaApplet.AddParam("Orientation", "String", "Vertical");
- } else {
- this.theJavaApplet.AddParam("Orientation", "String", "Horizontal");
- }
-
- this.theJavaApplet.AddParam("ButtonImage", "String", this.paramButtonImage);
- this.theJavaApplet.AddParam("HighliteImage", "String", this.paramHighliteImage);
- this.theJavaApplet.AddParam("TextJustification", "String", Integer.toString(this.textJustification));
- this.theJavaApplet.AddParam("TextAlignment", "String", Integer.toString(this.textAlignment));
- this.theJavaApplet.AddParam("ButtonFont", "String", this.buttonFont);
- this.theJavaApplet.AddParam("FontSize", "String", Integer.toString(this.fontSize));
- this.theJavaApplet.AddParam("FontColor", "String", Integer.toString(this.fontColor));
- this.theJavaApplet.AddParam("HighliteFontColor", "String", Integer.toString(this.highliteFontColor));
- if (this.bold) {
- this.theJavaApplet.AddParam("Bold", "String", "True");
- }
-
- if (this.italic) {
- this.theJavaApplet.AddParam("Italic", "String", "True");
- }
-
- if (this.backgroundStyle == 1) {
- this.theJavaApplet.AddParam("BackgroundColor", "String", Integer.toString(this.backgroundColor));
- } else if (this.backgroundStyle == 2) {
- this.theJavaApplet.AddParam("BackgroundImage", "String", this.paramBackgroundImage);
- }
-
- ButtonObject tempList = this.buttonList.getNext();
-
- for(int i = 0; tempList != null; ++i) {
- if (tempList.getSubButtonsExist()) {
- if (tempList.getText().compareTo("") == 0) {
- this.theJavaApplet.AddParam("ButtonText" + i, "String", " ");
- } else {
- this.theJavaApplet.AddParam("ButtonText" + i, "String", tempList.getText());
- }
-
- ButtonObject subList = tempList.getSubButtons().getNext();
-
- for(int j = 0; subList != null; ++j) {
- if (subList.getText().compareTo("") == 0) {
- this.theJavaApplet.AddParam("ButtonText" + i + "_" + j, "String", " ");
- this.theJavaApplet.AddParam("URL" + i + "_" + j, "String", " ");
- this.theJavaApplet.AddParam("Target" + i + "_" + j, "String", " ");
- } else {
- subList.setText(this.assMan.GetAssetName(Integer.parseInt(subList.getID(), 10)));
- this.theJavaApplet.AddParam("ButtonText" + i + "_" + j, "String", subList.getText());
- this.theJavaApplet.AddParam("URL" + i + "_" + j, "String", subList.getURL());
- this.theJavaApplet.AddParam("Target" + i + "_" + j, "String", subList.getTarget());
- }
-
- subList = subList.getNext();
- }
- } else {
- if (tempList.getText().compareTo("") == 0) {
- this.theJavaApplet.AddParam("ButtonText" + i, "String", " ");
- } else {
- String buttonText = this.assMan.GetAssetName(Integer.parseInt(tempList.getID(), 10));
- this.theJavaApplet.AddParam("ButtonText" + i, "String", buttonText);
- }
-
- this.theJavaApplet.AddParam("URL" + i, "String", tempList.getURL());
- this.theJavaApplet.AddParam("Target" + i, "String", tempList.getTarget());
- }
-
- tempList = tempList.getNext();
- }
-
- }
-
- private void updateSiteLook(int context) {
- DLayout layout = this.theJavaApplet.getLayout();
- DSite site = layout.getSite();
- DStyle style = site.getCurrentStyle();
- this.RemoveAssets();
- this.backgroundStyle = layout.getBackgroundStyle();
- if (this.backgroundStyle != 0) {
- if (this.backgroundStyle == 1) {
- this.backgroundColor = layout.getBackgroundColor();
- } else if (this.backgroundStyle == 2) {
- this.backID = this.assMan.AddAsset(layout.getBackgroundImage(), "Image", "");
- this.backgroundImage = this.assMan.GetAssetRelativeLocation(this.backID, context, 1);
- }
- } else {
- this.backgroundStyle = style.getBackgroundStyle();
- if (this.backgroundStyle == 1) {
- this.backgroundColor = style.getBackgroundColor();
- } else if (this.backgroundStyle == 2) {
- this.backID = this.assMan.AddAsset(style.getBackgroundImage(), "Image", ResourceBundle.getBundle("DynaButtonsComp").getString("Component_Name"));
- this.backgroundImage = this.assMan.GetAssetRelativeLocation(this.backID, context, 1);
- }
- }
-
- this.textJustification = 5;
- this.textAlignment = style.getButtonTextAlign();
- this.fontColor = style.getButtonFontColor();
- this.highliteFontColor = style.getButtonDownFontColor();
- DFont font = style.getButtonFont();
- this.buttonFont = font.getName();
- this.fontSize = font.getPoint();
- this.bold = font.getBold();
- this.italic = font.getItalic();
- String buttonUp = style.getButtonUpImage();
- if (buttonUp == null || buttonUp.compareTo("") == 0) {
- buttonUp = this.field_0 + "transButton.gif";
- }
-
- String buttonDown = style.getButtonDownImage();
- if (buttonDown == null || buttonDown.compareTo("") == 0) {
- buttonDown = this.field_0 + "transButton.gif";
- }
-
- this.upID = this.assMan.AddAsset(buttonUp, "Image", ResourceBundle.getBundle("DynaButtonsComp").getString("Component_Name"));
- this.downID = this.assMan.AddAsset(buttonDown, "Image", ResourceBundle.getBundle("DynaButtonsComp").getString("Component_Name"));
- this.ButtonImage = this.assMan.GetAssetRelativeLocation(this.upID, context, 1);
- this.HighliteImage = this.assMan.GetAssetRelativeLocation(this.downID, context, 1);
- DSize buttonSize = style.getButtonSize();
- if (buttonSize != null) {
- this.imgX = buttonSize.getWidth();
- this.imgY = buttonSize.getHeight();
- } else {
- this.imgX = 100;
- this.imgY = 35;
- }
-
- this.modifyImageSize();
- }
- }
-